package com.gopay.scheduler.job;

import com.gopay.scheduler.GopayBaseJob;
import com.gopay.scheduler.service.qualifications.OverQualificationsInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;

import javax.annotation.Resource;
import java.util.Calendar;

/**
 * CLASSNAME:AutoGenQualificationsJob
 * Description:一周之内即将过期的企业信息
 * DATE:2017/5/2/002
 * AUTHER:PANSHICHAO
 * www.gopay.com.cn Inc.All rights reserved.
 */
public class AutoGenQualificationsJob extends GopayBaseJob {
    @Resource(name="overQualificationsInfoService")
    private OverQualificationsInfoService overQualificationsInfoService;

    @Value("#{webProperties['auto.qualifications.email']}")
    private String email;

    private Logger logger = LoggerFactory.getLogger(this.getClass());
    @Override
    protected void doJobInternal() {
        logger.error("资质过期任务开始");
            try {
                Calendar now = Calendar.getInstance();
                boolean isFirstSunday = (now.getFirstDayOfWeek() == Calendar.SUNDAY);
                int weekDay = now.get(Calendar.DAY_OF_WEEK);
                if(isFirstSunday){
                    weekDay = weekDay - 1;
                    if(weekDay == 0){
                        weekDay = 7;
                    }
                }
                if(weekDay !=6 || weekDay !=7){
                    overQualificationsInfoService.sendMail(email);
                }else{
                    logger.error("当前为休息日，资质任务不执行！");
                }
            } catch (Exception e) {
                logger.error("过期资质邮件发送失败！"+e.getMessage());
                logger.error("资质过期任务结束");
            }

    }
}
